#!/usr/bin/env python2.5
# encoding: utf-8
"""
StreamLoader.py

Created by Alakazam on 2007-07-05.
Copyright (c) 2007 . All rights reserved.
"""

import csv, sys, os, re

class StreamExporter(object):
  def __init__(self, sourceStream, targetFile, startTime = None, endTime = None):
    self.sourceStream = sourceStream
    self.csvwriter  = csv.writer(file(targetFile, "w"))
    
    if startTime == None:
      self.startTime  = self.sourceStream.getFirstStart()
    else:
      self.startTime  = startTime
    
    if endTime == None:
      self.endTime    = self.sourceStream.getLastEnd()
    else:
      self.endTime    = endTime
  
  def run(self):
    self.csvwriter.writerows(self.sourceStream[self.startTime:self.endTime])
  
